
all: release

test:
	@ [ -d bin-Release ] && \
		( \
			./bin-Release/graph ./test/essai1.c; \
			./bin-Release/graph ./test/essai2.c; \
			./bin-Release/graph ./test/essai3.c; \
			make convert || echo "Fail"; \
		) || \
		( [ -d bin-Debug ] && \
			( \
				./bin-Debug/graph ./test/essai1.c; \
				./bin-Debug/graph ./test/essai2.c; \
				./bin-Debug/graph ./test/essai3.c; \
				make convert || echo "Fail"; \
			) \
		) || make all test; \

convert:
	@ [ -x "$$(which convert)" ] && \
		( \
			for file in $$(ls test/*.dot); do \
				name="$$(echo $$file | sed 's/dot$$/png/')"; \
				echo "$$file -> $$name"; \
				convert $$file $$name; \
			done; \
		) || \
		echo "Unable to find convert executable."

debug:
	@ mkdir -p build-Debug
	@ cd build-Debug && \
		cmake -DCMAKE_BUILD_TYPE=Debug .. && \
		make -j8

release:
	@ mkdir -p build-Release
	@ cd build-Release && \
		cmake -DCMAKE_BUILD_TYPE=Release .. && \
		make -j8

clean:
	git clean -f

mrproper:
	git clean -xdf

.PHONY: all release clean debug test convert
